home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / mhs_c.arc / OUTPOST.ARC / OUTFILE.C < prev    next >
C/C++ Source or Header  |  1988-06-27  |  2KB  |  107 lines

  1. /* ******************************* OUTFILE.C ****************************** */
  2. #include "cctypes.h"
  3.  
  4. extern int OutFile;
  5. extern int InFile;
  6. extern char OutExtension[];
  7. extern int ErrorsInThisFile;
  8. extern int WarningsInThisFile;
  9. extern char InFileName[];
  10. extern char OutFileName[];
  11. extern long fileSize;
  12. extern int contentsWritten;
  13. extern char messageBuffer[];
  14.  
  15. extern FILEINFO fileInfo;
  16. extern char *XRBRec[];
  17.  
  18. void BlankLine();
  19. void WriteIt();
  20.  
  21. int SetUpOutFile()
  22. {
  23.     int ccode;
  24.  
  25.     /* open the output file */
  26.     ccode = OpenOutputFile(OutExtension);
  27.         
  28.     if ( ccode)
  29.         return(CANNOT_CREATE_OUTPUT);
  30.  
  31.     WriteIt("Message:");
  32.     BlankLine();
  33.  
  34.     return(0);
  35. }
  36.  
  37. void BlankLine()
  38. {
  39.     write(OutFile, "\15\12", 2); /* CR-LF */
  40. }
  41.  
  42. void WriteIt(string)
  43. char *string;
  44. {
  45.     write(OutFile, string, strlen(string));
  46. }
  47.  
  48. int WriteCCMFileMsg() /* saved for last */
  49. {
  50.     char ch[3];
  51.     int bytes = 0, returnCode = 0, temp, ccode;
  52.     long fPtr = 0L;
  53.  
  54.     /* first, close the .XRB file */
  55.     close(InFile);
  56.  
  57.     if ( !contentsWritten ) {
  58.         contentsWritten++;
  59.         WriteIt("Contents:");
  60.         BlankLine();
  61.     }
  62.  
  63.     /* get the message from the SMF file */
  64.     sprintf(InFileName, "Q:OUT\\%s", fileInfo.fileName);
  65.     ccode = OpenInputFile();
  66.     if ( ccode ) {
  67.         Error(CANNOT_OPEN_FILE);
  68.         goto Out;
  69.     }
  70.  
  71.     /* determine where the message begins */
  72.     /* it begins where the message header ends - <LF><LF> or <LF><CR><LF> */
  73.     fPtr = lseek(InFile, 128L, 0);
  74.     while (1) {
  75.         if ( read(InFile, ch, 1) == 0 ) goto NoMessage;
  76.         if ( ch[0] == (char)10 ) {
  77.             if ( read(InFile, ch, 1) == 0 ) goto NoMessage;
  78.             if ( ch[0] == (char)13 ) 
  79.                 if ( read(InFile, ch, 1) == 0 ) goto NoMessage;
  80.             if ( ch[0] == (char)10 )
  81.                 break;
  82.         }
  83.     }
  84.  
  85.     temp = strlen(messageBuffer);
  86.  
  87.     bytes = read(InFile, &messageBuffer[temp - 1],
  88.             MESSAGE_SIZE - temp);
  89.     messageBuffer[temp+bytes-1] = '\0';
  90.     WriteIt("Text item:");
  91.     BlankLine();
  92.  
  93. NoMessage:
  94.     if ( strlen(messageBuffer) )
  95.         WriteIt(messageBuffer);
  96.  
  97.     fileSize = lseek(OutFile,(long)0,2);
  98.     close(OutFile); /* close the .CCM file */
  99.     close(InFile); /* close the SMF file */
  100.     if ( fileSize == 0L ) 
  101.         returnCode = -1;
  102. Out:
  103.     return(returnCode);
  104. }
  105.  
  106.  
  107.